/**
 * 远程服务调用代理.
 *
 * @author guojunlong@tuniu.com (Allen Guo)
 * @since 2016-10-19
 * @copyright Copyright &copy; 2006-2016 Tuniu.com
 */
'use strict';
const RemoteClient = require('@tuniu/remote-client');
module.exports = class {
    __construct() {
        let options = {};
        if(this.ctx.tspClient && this.ctx.tspClient.caller) {
            options.tspCaller = this.ctx.tspClient.caller;
        }
        this.remoteClient = RemoteClient(this.ctx.config.remote, options);
    }
    requestP(service, paramsObj, options) {
        options = options || {};
        options.headers = options.headers || {};
        if (this.ctx.req) {
            options.headers['x-request-id'] = this.ctx.req.id;
        }
        return this.remoteClient.invoke(service, paramsObj, options);
    }
}